import {getToken} from "@/utils/auth";

export const GotoYsdMixins = {
  props: {
  },
  components:{
  },
  data() {
    return {
      //当前菜单路径
      menuLevels:''
    }
  },
  created() {
    //获取菜单路径
    let matcheds = this.$route.matched.filter(item => item.meta && item.meta.title)
    for(let i = 0; i < matcheds.length; i++) {
      let obj = matcheds[i];
      if(obj.meta.title){
        if(this.menuLevels) this.menuLevels+="/";
        this.menuLevels += obj.meta.title;
      }
    }
  },
  computed: {
  },
  methods: {
    /**
     * 跳转配置
     */
    gotoSet(apiCode,levels) {
      if(this.isEmpty(levels)){
        levels = this.$route.query.levels;
      }
      /**
       * 低零代码平台Token信息
       * key：在header中的属性名
       * val：在header中的token值
       */
      let tokenInfo = {
        key: 'Authorization',
        val: 'Bearer ' + getToken()
      }
      //加密
      let ciphertext = window.btoa(JSON.stringify(tokenInfo));
      //访问地址
      if(this.isEmpty(this.$store.getters.YSD_BASE_URL)){
        this.msgError("未获取优树搭服务访问地址！");
        return;
      }
      let url = this.$store.getters.YSD_BASE_URL + `/MksAdmin/index.html?token=${ciphertext}&levels=${levels}`;
      if(this.isNotEmpty(apiCode)){
        url += `&procTarget=${apiCode}`;
      }
      //以新窗口打开Java 图形化编程平台
      window.open(url)
    },
  },
  watch:{
  }
}
